<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#assign css>
<#--此ftl中用到的css-->

<link rel="stylesheet" href="/assets/vendor/bootstrap-tagsinput/bootstrap-tagsinput.css">
<link rel="stylesheet" href="/assets/vendor/iCheck/all.css">

<style>


    .bootstrap-tagsinput{
        width:100%;
    }
    .bootstrap-tagsinput input{
        width:100%;
    }
</style>

</#assign>

<#assign js>

<script src="/assets/vendor/bootstrap-tagsinput/bootstrap-tagsinput.js" ></script>
<script src="/assets/vendor/iCheck/icheck.js" ></script>

<#--此ftl中用到的js-->
<script>
	$("#btn-submit").click(function () {
		// 校验表单合法
		var bootstrapValidator = $(".form-edit").data('bootstrapValidator');
		bootstrapValidator.validate();
		if(bootstrapValidator.isValid()){
			$.ajax({
				type: "POST",
				url: "/category/edit",
				data: $(".form-edit").serialize(),
				dataType: "JSON",
				success: function(res){
					layer.msg(res.message, {time: 2000
					}, function(){
						location.href="/category/index";
					});
				}
			});
		}else{
			return false;
		}
	});

    $(function () {
        var type = '${categoryCfg.type!}';
        if(type!='3') $("#hotGoodsDiv").hide();

        //初始化InputMask控件

        //iCheck for checkbox and radio inputs
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass: 'iradio_minimal-blue'
        })
        //Red color scheme for iCheck
        $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
            checkboxClass: 'icheckbox_minimal-red',
            radioClass: 'iradio_minimal-red'
        })
        //Flat red color scheme for iCheck
        $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
            checkboxClass: 'icheckbox_flat-green',
            radioClass: 'iradio_flat-green'
        })


    });


    $("#type").change(function (e) {
        debugger;
        var type = e.currentTarget.value;
        if(type=='3'){
            $("#hotGoodsDiv").show();
        }else{
            $("#hotGoodsDiv").hide();
        }

    });
    function tips(){
        var masterRate = $("#drawRate").val();//师傅提成比例
        if(masterRate==''){
            masterRate = 0;
        }
        var agentRate  = (100 - ${platRate} - masterRate).toFixed(2);
        layer.tips('平台提成比例：${platRate}%<br/>' +
                '分站提成比例：'+agentRate+'%<br/>' +
                '师傅提成比例：'+masterRate+'%', '#tipsButton', {
            tips: [1, '#3595CC'],
            time: 5000
        });
    }

	$('.form-edit').bootstrapValidator({
		message: '请输入有效值',
		feedbackIcons: {
			valid: 'glyphicon glyphicon-ok',
			invalid: 'glyphicon glyphicon-remove',
			validating: 'glyphicon glyphicon-refresh'
		}
	});


</script>
</#assign>
<@layout title="编辑" active="category">
<!-- Content Header (Page header) -->
<section class="content-header">
	<h1>
		<#if isAdd>
            新增
        <#else>
            编辑
        </#if>
		<small>物品品类详细信息</small>
	</h1>
	<ol class="breadcrumb">
		<li><a href="/"><i class="fa fa-home"></i> 管理后台</a></li>
		<li><a href="/category/index"><i class="fa fa-list-ul"></i> 跑腿业务设置</a></li>
		<li class="active"><i class="fa fa-edit"></i>
		    <#if isAdd>
                新增
            <#else>
                编辑
            </#if>
		</li>
	</ol>
</section>
<!-- Main content -->
<section class="content">
	<div class="row">
		<div class="col-md-12">
			<!-- Default box -->
			<div class="box  box-primary">
				<form class="form-horizontal form-edit" method="post" action="category/edit" onkeydown="if(event.keyCode==13){return false}">
					<div class="box-body">
						<input type="hidden" id="id" name="id" value="${categoryCfg.id!}">
						<input type="hidden" id="isAdd" name="isAdd" value="${isAdd?string('true','false')}">
						<#--<div class="form-group">
							<label class="col-sm-2 control-label">分站id：</label>
							<div class="col-sm-10">
								<input required placeholder="请输入分站id" id="agentId" name="agentId" class="form-control" type="text" value="${categoryCfg.agentId!}" >
							</div>
						</div>-->

							<div class="form-group">
                                <label class="col-sm-3 control-label">所属服务类型：</label>
                                <div class="col-sm-4" >
                                    <select name="type" id="type" class="form-control" required disabled>
                                        <option value="">请选择</option>
                                        <option value="1" <#if categoryCfg.type??&&categoryCfg.type == 1>selected</#if>>帮我送</option>
                                        <option value="2" <#if categoryCfg.type??&&categoryCfg.type ==2>selected</#if>>帮我取</option>
                                        <option value="3" <#if categoryCfg.type??&&categoryCfg.type == 3>selected</#if>>随意购</option>

                                    </select>
                                    <input name="type" value="${categoryCfg.type}" type="hidden">
                                </div>

							</div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">分类名称：</label>
                            <div class="col-sm-4">
                                <#--<input required placeholder="请输入分类名称" id="category" name="category" class="form-control" type="text" value="${categoryCfg.category!}" >-->
                                <select name="category" required class="form-control">
                                    <#list noAddList as category>
                                        <option value="${category.id}">${category.category}</option>

                                    </#list>

                                </select>
                            </div>
                        </div>
                        <div class=" form-group">
                            <label class="col-sm-3 control-label">起步里程（KM）：</label>
                            <div class="col-sm-4">
                                <input required placeholder="请输入起步里程" id="initiateKm" name="initiateKm" class="form-control" type="text" value="${categoryCfg.initiateKm?string('0.##')}" >
                            </div>
                        </div>
                        <div class=" form-group">
                            <label class="col-sm-3 control-label">起步价（元）：</label>
                            <div class="col-sm-4">
                                <input required placeholder="请输入起步价" id="initiatePrice" name="initiatePrice" class="form-control" type="text" value="${categoryCfg.initiatePrice?string('0.##')!}" >
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-3 control-label">起步里程外每公里单价（元）：</label>
                            <div class="col-sm-4">
                                <input required placeholder="起步里程外每公里单价" id="overInitKmPrice" name="overInitKmPrice" class="form-control" type="text" value="${(categoryCfg.overInitKmPrice?string('0.##'))!}" >
                            </div>

                        </div>
                        <div class="form-group">

                            <label class="col-sm-3 control-label">超出里程（KM）：</label>
                            <div class="col-sm-4">
                                <input required placeholder="请输入超出里程" id="exceedKm" name="exceedKm" class="form-control" type="text" value="${categoryCfg.exceedKm?string('0.##')!}" >
                            </div>
                        </div>

                        <div class="form-group">

                            <label class="col-sm-3 control-label">超出里程每公里额外加价（元）：</label>
                            <div class="col-sm-4">
                                <input required placeholder="请输入超出里程每公里额外加价" id="exceedExtraPrice" name="exceedExtraPrice" class="form-control" type="text" value="${categoryCfg.exceedExtraPrice?string.number!}" >
                            </div>

                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">配送起始重量（KG）：</label>
                            <div class="col-sm-4">
                                <input required placeholder="请输入配送起始重量" id="weightBegin" name="weightBegin" class="form-control" type="text" value="${categoryCfg.weightBegin?string('0.##')!}" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">配送最高重量（KG）：</label>
                            <div class="col-sm-4">
                                <input required placeholder="请输入最高重量" id="weightEnd" name="weightEnd" class="form-control" type="text" value="${categoryCfg.weightEnd?string('0.##')!}" >
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">超重后每公斤费用（元）：</label>
                            <div class="col-sm-4">
                                <input required placeholder="请输入超重后每公斤费用" id="weightExtraPrice" name="weightExtraPrice" class="form-control" type="text" value="${categoryCfg.weightExtraPrice?string('0.##')!}" >
                            </div>

                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">最低保价（元）：</label>
                            <div class="col-sm-4">
                                <input required placeholder="请输入最低保价" id="parcelInsuBegin" name="parcelInsuBegin" class="form-control" type="text" value="${categoryCfg.parcelInsuBegin?string('0.##')!}" >
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">保价最高（元）：</label>
                            <div class="col-sm-4">
                                <input required placeholder="请输入保价最高" id="parcelInsuEnd" name="parcelInsuEnd" class="form-control" type="text" value="${categoryCfg.parcelInsuEnd?string('0.##')!}" >
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">保费比例（%）：</label>
                            <div class="col-sm-4">
                                <input required placeholder="请输入保费比例" id="parcelInsuRate" name="parcelInsuRate" class="form-control" type="text" value="${categoryCfg.parcelInsuRate?string('0.##')!}" >
                            </div>

                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">师傅提成比例（%）：</label>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <input required placeholder="请输入师傅提成比例" id="drawRate" name="drawRate" class="form-control" required type="numeric" value="${(categoryCfg.drawRate?string('0.##'))!}" min="0" max="${maxRate}" >
                                    <div class="input-group-btn">
                                        <!-- Buttons -->
                                        <button type="button" id="tipsButton" onclick="tips()" class="btn btn-default" >
                                            <span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span>
                                        </button>
                                    </div>
                                </div>
                            </div>

                        </div>
                        <div id="hotGoodsDiv">
                            <div class="form-group" >
                                <label class="col-sm-3 control-label">热门商品设置:</label>
                                <div class="col-sm-6">
                                    <input data-role="tagsinput" type="text" name="hotGoods" placeholder="请输入热门商品，输入完成后点击鼠标即可" value="${categoryCfg.hotGoods!}" class="col-sm-10 form-control" id="hotGoods">
                                </div>
                            </div>
                            <div class="form-group" >
                                <label class="col-sm-3 control-label">请选择分类图标:</label>
                                <div class="col-sm-6">
                                    <#list icons as icon>
                                        <input type="radio" name="icon" class="flat-red" value="${icon.id}" <#if categoryCfg.icon?? && categoryCfg.icon==icon.icon>checked</#if>>
                                        <image src="/${icon.icon!}" title="${icon.notes}" style="height: 40px;width: 40px;"></image>

                                    </#list>
                                </div>
                            </div>
                        </div>





					<div class="box-footer">
						<button type="button" class="btn btn-default btn-back">返回</button>

						<button type="button" class="btn btn-info pull-right" id="btn-submit">提交</button>
					</div>

				</form>
			</div>
			<!-- /.box -->
		</div>
	</div>
</section>
<!-- /.content -->
</@layout>
